package stream;

import stream.model.Student;

import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

public class Demo02 {
    public static void main(String[] args) {
        List<Student> studentList = new ArrayList<>();
        studentList.add(new Student(1, "张三", "M", 19));
        studentList.add(new Student(1, "李四", "M", 18));
        studentList.add(new Student(1, "王五", "F", 21));
        studentList.add(new Student(1, "赵六", "F", 20)); //条件筛选

        List<String> collect = studentList.stream()
                .filter(student -> student.getAge() > 20) //过滤出年龄小于20岁的学生
                .sorted(Comparator.comparing(Student::getAge)) //对结果进行排序
                .map(Student::getName)// 提取出结合中的name属性
                .collect(Collectors.toList()); //转换成一个新的集合
        System.out.println(collect);
    }
}
